<html>
<head><meta charset="utf-8"><title>Debug vs Release opts · t-compiler/wg-mir-opt · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/189540-t-compiler/wg-mir-opt/index.html">t-compiler/wg-mir-opt</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/189540-t-compiler/wg-mir-opt/topic/Debug.20vs.20Release.20opts.html">Debug vs Release opts</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="198457033"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189540-t-compiler/wg-mir-opt/topic/Debug%20vs%20Release%20opts/near/198457033" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Félix Fischer <a href="https://rust-lang.github.io/zulip_archive/stream/189540-t-compiler/wg-mir-opt/topic/Debug.20vs.20Release.20opts.html#198457033">(May 22 2020 at 15:46)</a>:</h4>
<p>Correct me if I'm wrong here.<br>
My understanding is that currently, we have 3 "levels" of optimizations in MIR:</p>
<ul>
<li>Level 1: always on. These are <strong>sound</strong> and <strong>tend to improve compilation times in debug</strong></li>
<li>Level 2: useable on nightly. Some are <strong>unsound</strong>, some are <strong>unstable</strong>, and some <strong>are sound but don't improve debug compilation times</strong></li>
<li>Level 3: same as Level 2, more or less?</li>
</ul>
<p>What I think we could use, is having an enum-based opt mode instead of a level-based opt mode:</p>
<ul>
<li><strong>Debug</strong>: optimizations that <strong>improve compilation times in debug mode</strong>. All sound. Engaged in <code>--debug</code> mode.</li>
<li><strong>Release</strong>: optimizations that either <strong>improve compilation times</strong> or <strong>improve runtime performance</strong> in release mode. All <strong>sound</strong>. Engaged in <code>--release</code> mode.</li>
<li><strong>Unstable</strong>: optimizations that are either just <strong>unstable</strong> or still <strong>unsound</strong>. Never engaged, except for testing purposes.</li>
</ul>
<p><strong>Debug</strong> would more or less reflect our current <strong>Level 1</strong>. <strong>Release</strong> would allow us to start using optimizations that improve compilation times in release mode, like inlining (cc <span class="user-mention" data-user-id="125250">@Wesley Wiser</span>, you have experience in this example case :3). It would also allow us to use many opts that are currently chilling on level 2 or 3, which are sound and stable but otherwise not useable in Debug because the CGU partitioning scheme makes them a compile-time regression on Debug builds.</p>
<p>Edit: I'm thinking in <code>cargo</code> terms for <code>debug</code> and <code>release</code> modes. Maybe <code>--debug</code> mode would equal <code>opt-level=0</code> and <code>--release</code> mode would equal <code>opt-level=3</code> here. Thanks <span class="user-mention" data-user-id="211727">@Jonas Schievink</span> for pointing it out <span aria-label="heart" class="emoji emoji-2764" role="img" title="heart">:heart:</span></p>



<a name="198457353"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189540-t-compiler/wg-mir-opt/topic/Debug%20vs%20Release%20opts/near/198457353" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Félix Fischer <a href="https://rust-lang.github.io/zulip_archive/stream/189540-t-compiler/wg-mir-opt/topic/Debug.20vs.20Release.20opts.html#198457353">(May 22 2020 at 15:49)</a>:</h4>
<p>CC <span class="user-mention" data-user-id="124288">@oli</span></p>



<a name="198457901"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189540-t-compiler/wg-mir-opt/topic/Debug%20vs%20Release%20opts/near/198457901" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jonas Schievink  [he/him] <a href="https://rust-lang.github.io/zulip_archive/stream/189540-t-compiler/wg-mir-opt/topic/Debug.20vs.20Release.20opts.html#198457901">(May 22 2020 at 15:53)</a>:</h4>
<p>Note that rustc doesn't have a <code>--release</code> mode, it has opt-level=0,1,2,3,s,z instead</p>



<a name="198458008"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189540-t-compiler/wg-mir-opt/topic/Debug%20vs%20Release%20opts/near/198458008" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Félix Fischer <a href="https://rust-lang.github.io/zulip_archive/stream/189540-t-compiler/wg-mir-opt/topic/Debug.20vs.20Release.20opts.html#198458008">(May 22 2020 at 15:54)</a>:</h4>
<p>Oh really? Lol, I'm clearly using cargo too much <span aria-label="laughter tears" class="emoji emoji-1f602" role="img" title="laughter tears">:laughter_tears:</span></p>



<a name="198458081"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189540-t-compiler/wg-mir-opt/topic/Debug%20vs%20Release%20opts/near/198458081" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Félix Fischer <a href="https://rust-lang.github.io/zulip_archive/stream/189540-t-compiler/wg-mir-opt/topic/Debug.20vs.20Release.20opts.html#198458081">(May 22 2020 at 15:54)</a>:</h4>
<p>Still, don't people mainly use <code>cargo</code>? What's up with opt-levels being different in rustc and cargo? That's kinda weird</p>



<a name="198458194"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189540-t-compiler/wg-mir-opt/topic/Debug%20vs%20Release%20opts/near/198458194" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jonas Schievink  [he/him] <a href="https://rust-lang.github.io/zulip_archive/stream/189540-t-compiler/wg-mir-opt/topic/Debug.20vs.20Release.20opts.html#198458194">(May 22 2020 at 15:55)</a>:</h4>
<p>opt-levels are configurable in Cargo, it just defaults to 0 and 3 for the dev and release profiles, respectively</p>



<a name="198458318"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189540-t-compiler/wg-mir-opt/topic/Debug%20vs%20Release%20opts/near/198458318" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jonas Schievink  [he/him] <a href="https://rust-lang.github.io/zulip_archive/stream/189540-t-compiler/wg-mir-opt/topic/Debug.20vs.20Release.20opts.html#198458318">(May 22 2020 at 15:56)</a>:</h4>
<p>To some degree I guess it's something rustc inherited from C compilers</p>



<a name="198458341"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189540-t-compiler/wg-mir-opt/topic/Debug%20vs%20Release%20opts/near/198458341" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Félix Fischer <a href="https://rust-lang.github.io/zulip_archive/stream/189540-t-compiler/wg-mir-opt/topic/Debug.20vs.20Release.20opts.html#198458341">(May 22 2020 at 15:56)</a>:</h4>
<p>Yeah, it feels a lot that way :3</p>



<a name="198458373"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189540-t-compiler/wg-mir-opt/topic/Debug%20vs%20Release%20opts/near/198458373" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Félix Fischer <a href="https://rust-lang.github.io/zulip_archive/stream/189540-t-compiler/wg-mir-opt/topic/Debug.20vs.20Release.20opts.html#198458373">(May 22 2020 at 15:57)</a>:</h4>
<p>That feels very <code>gcc -OX ...</code></p>



<a name="198458745"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189540-t-compiler/wg-mir-opt/topic/Debug%20vs%20Release%20opts/near/198458745" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Félix Fischer <a href="https://rust-lang.github.io/zulip_archive/stream/189540-t-compiler/wg-mir-opt/topic/Debug.20vs.20Release.20opts.html#198458745">(May 22 2020 at 15:59)</a>:</h4>
<p>Kay, updated the original post to reflect that. Thank you Jonas :)</p>



<a name="198531640"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189540-t-compiler/wg-mir-opt/topic/Debug%20vs%20Release%20opts/near/198531640" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> eddyb <a href="https://rust-lang.github.io/zulip_archive/stream/189540-t-compiler/wg-mir-opt/topic/Debug.20vs.20Release.20opts.html#198531640">(May 23 2020 at 11:46)</a>:</h4>
<p>it <em>is</em> GCC/Clang -O</p>



<a name="198531650"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189540-t-compiler/wg-mir-opt/topic/Debug%20vs%20Release%20opts/near/198531650" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> eddyb <a href="https://rust-lang.github.io/zulip_archive/stream/189540-t-compiler/wg-mir-opt/topic/Debug.20vs.20Release.20opts.html#198531650">(May 23 2020 at 11:47)</a>:</h4>
<p>idk why we call the "dev" Cargo profile "Debug mode" colloquially :P</p>



<a name="198531698"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189540-t-compiler/wg-mir-opt/topic/Debug%20vs%20Release%20opts/near/198531698" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> eddyb <a href="https://rust-lang.github.io/zulip_archive/stream/189540-t-compiler/wg-mir-opt/topic/Debug.20vs.20Release.20opts.html#198531698">(May 23 2020 at 11:48)</a>:</h4>
<p>dev/release is inherited from... other language package managers, I'm guessing? it's not a compiler concept, although there is some implication that you'd want optimizations in release mode</p>



<a name="198531700"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189540-t-compiler/wg-mir-opt/topic/Debug%20vs%20Release%20opts/near/198531700" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> eddyb <a href="https://rust-lang.github.io/zulip_archive/stream/189540-t-compiler/wg-mir-opt/topic/Debug.20vs.20Release.20opts.html#198531700">(May 23 2020 at 11:48)</a>:</h4>
<p>but something likely more meaningful is how <code>debug!</code> logging w/ the <code>log</code> crate is disabled in release builds</p>



<a name="198531705"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189540-t-compiler/wg-mir-opt/topic/Debug%20vs%20Release%20opts/near/198531705" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> eddyb <a href="https://rust-lang.github.io/zulip_archive/stream/189540-t-compiler/wg-mir-opt/topic/Debug.20vs.20Release.20opts.html#198531705">(May 23 2020 at 11:49)</a>:</h4>
<p>(same with <code>debug_assert!</code>, which I keep forgetting exists)</p>



<a name="198531710"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189540-t-compiler/wg-mir-opt/topic/Debug%20vs%20Release%20opts/near/198531710" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> eddyb <a href="https://rust-lang.github.io/zulip_archive/stream/189540-t-compiler/wg-mir-opt/topic/Debug.20vs.20Release.20opts.html#198531710">(May 23 2020 at 11:49)</a>:</h4>
<p>you can think of that "you're releasing this to end-users, so you want it to be fast and it doesn't necessarily need to be debuggable"</p>



<a name="198531753"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189540-t-compiler/wg-mir-opt/topic/Debug%20vs%20Release%20opts/near/198531753" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> eddyb <a href="https://rust-lang.github.io/zulip_archive/stream/189540-t-compiler/wg-mir-opt/topic/Debug.20vs.20Release.20opts.html#198531753">(May 23 2020 at 11:50)</a>:</h4>
<p>(but as <span class="user-mention" data-user-id="211727">@Jonas Schievink</span> mentioned, you can control both opt levels and debuginfo and I think maybe even debug assertions through Cargo profiles. there's no custom profiles... yet, although I know I few places which direly need them)</p>



<a name="198531820"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189540-t-compiler/wg-mir-opt/topic/Debug%20vs%20Release%20opts/near/198531820" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> eddyb <a href="https://rust-lang.github.io/zulip_archive/stream/189540-t-compiler/wg-mir-opt/topic/Debug.20vs.20Release.20opts.html#198531820">(May 23 2020 at 11:52)</a>:</h4>
<p>/me is somewhat opposed to a debug/release optimization split, especially if debuginfo is involved, since I want to preserve debuginfo through as many optimizations as possible</p>



<a name="198531837"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189540-t-compiler/wg-mir-opt/topic/Debug%20vs%20Release%20opts/near/198531837" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> eddyb <a href="https://rust-lang.github.io/zulip_archive/stream/189540-t-compiler/wg-mir-opt/topic/Debug.20vs.20Release.20opts.html#198531837">(May 23 2020 at 11:53)</a>:</h4>
<p><span class="user-mention" data-user-id="212698">@Félix Fischer</span> however, I do like the unstable/unsound and compile-time vs run-time distinctions</p>



<a name="198531845"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189540-t-compiler/wg-mir-opt/topic/Debug%20vs%20Release%20opts/near/198531845" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> eddyb <a href="https://rust-lang.github.io/zulip_archive/stream/189540-t-compiler/wg-mir-opt/topic/Debug.20vs.20Release.20opts.html#198531845">(May 23 2020 at 11:53)</a>:</h4>
<p>there should probably be a clear dedicated opt-in for "known to be unsound"</p>



<a name="198531901"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189540-t-compiler/wg-mir-opt/topic/Debug%20vs%20Release%20opts/near/198531901" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> eddyb <a href="https://rust-lang.github.io/zulip_archive/stream/189540-t-compiler/wg-mir-opt/topic/Debug.20vs.20Release.20opts.html#198531901">(May 23 2020 at 11:55)</a>:</h4>
<p>frankly that's all we need to do, and maybe remove level -Zmir-opt-level=3?</p>



<a name="198531947"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189540-t-compiler/wg-mir-opt/topic/Debug%20vs%20Release%20opts/near/198531947" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> eddyb <a href="https://rust-lang.github.io/zulip_archive/stream/189540-t-compiler/wg-mir-opt/topic/Debug.20vs.20Release.20opts.html#198531947">(May 23 2020 at 11:57)</a>:</h4>
<p>as for using an <code>enum</code>, it could be this:</p>
<div class="codehilite"><pre><span></span><code><span class="k">enum</span> <span class="nc">MirOptLevel</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">    </span><span class="n">Disabled</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="mi">0</span><span class="p">,</span><span class="w"></span>
<span class="w">    </span><span class="nb">Default</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="mi">1</span><span class="p">,</span><span class="w"></span>
<span class="w">    </span><span class="n">Aggressive</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="mi">2</span><span class="p">,</span><span class="w"></span>
<span class="p">}</span><span class="w"></span>
</code></pre></div>



<a name="198532013"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189540-t-compiler/wg-mir-opt/topic/Debug%20vs%20Release%20opts/near/198532013" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> bjorn3 <a href="https://rust-lang.github.io/zulip_archive/stream/189540-t-compiler/wg-mir-opt/topic/Debug.20vs.20Release.20opts.html#198532013">(May 23 2020 at 11:59)</a>:</h4>
<p>Can we also have a flag to specify the optimizations to run rather than choose a fixed combination? For example enable const-prop and inlining, but not copy-prop.</p>



<a name="198546400"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189540-t-compiler/wg-mir-opt/topic/Debug%20vs%20Release%20opts/near/198546400" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Félix Fischer <a href="https://rust-lang.github.io/zulip_archive/stream/189540-t-compiler/wg-mir-opt/topic/Debug.20vs.20Release.20opts.html#198546400">(May 23 2020 at 18:28)</a>:</h4>
<p><span class="user-mention" data-user-id="133247">@bjorn3</span> sure. That makes a lot of sense, specially for testing and for keeping the optimization suite as a whole sound over time.</p>



<a name="198546494"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189540-t-compiler/wg-mir-opt/topic/Debug%20vs%20Release%20opts/near/198546494" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Félix Fischer <a href="https://rust-lang.github.io/zulip_archive/stream/189540-t-compiler/wg-mir-opt/topic/Debug.20vs.20Release.20opts.html#198546494">(May 23 2020 at 18:31)</a>:</h4>
<p>(@eddyb)</p>
<blockquote>
<p>/me is somewhat opposed to a debug/release optimization split, especially if debuginfo is involved, since I want to preserve debuginfo through as many optimizations as possible</p>
</blockquote>
<p>I agree with you here, which makes me think that maybe we want a third, different compilation mode that's just for getting that extra 0.5% of performance out of the program:</p>
<ul>
<li>Debug: fast to compile</li>
<li>Release: apply all opts, except ones that remove debug info</li>
<li>Release-forget-debugging: Release, and remove debug info</li>
</ul>



<a name="198571638"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189540-t-compiler/wg-mir-opt/topic/Debug%20vs%20Release%20opts/near/198571638" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/189540-t-compiler/wg-mir-opt/topic/Debug.20vs.20Release.20opts.html#198571638">(May 24 2020 at 07:49)</a>:</h4>
<p><span class="user-mention silent" data-user-id="119009">eddyb</span> <a href="#narrow/stream/189540-t-compiler.2Fwg-mir-opt/topic/Debug.20vs.20Release.20opts/near/198531845">said</a>:</p>
<blockquote>
<p>there should probably be a clear dedicated opt-in for "known to be unsound"</p>
</blockquote>
<p>really? IMO "known to be unsound" optimizations should just <em>not happen</em>, period. when we find a soundness issue, we either fix it or remove the offending optimization.</p>



<a name="198595417"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189540-t-compiler/wg-mir-opt/topic/Debug%20vs%20Release%20opts/near/198595417" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Félix Fischer <a href="https://rust-lang.github.io/zulip_archive/stream/189540-t-compiler/wg-mir-opt/topic/Debug.20vs.20Release.20opts.html#198595417">(May 24 2020 at 19:02)</a>:</h4>
<p>^</p>



<a name="198595428"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189540-t-compiler/wg-mir-opt/topic/Debug%20vs%20Release%20opts/near/198595428" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Félix Fischer <a href="https://rust-lang.github.io/zulip_archive/stream/189540-t-compiler/wg-mir-opt/topic/Debug.20vs.20Release.20opts.html#198595428">(May 24 2020 at 19:04)</a>:</h4>
<p>I mean... I'm imagining that just as there are clippy lints that are not really that great but some people want anyway, because they work for their setup or whatever, someone could want an optimization that happens to work soundly for their use case.</p>



<a name="198595467"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189540-t-compiler/wg-mir-opt/topic/Debug%20vs%20Release%20opts/near/198595467" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Félix Fischer <a href="https://rust-lang.github.io/zulip_archive/stream/189540-t-compiler/wg-mir-opt/topic/Debug.20vs.20Release.20opts.html#198595467">(May 24 2020 at 19:04)</a>:</h4>
<p>However there's a big difference</p>



<a name="198595472"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189540-t-compiler/wg-mir-opt/topic/Debug%20vs%20Release%20opts/near/198595472" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Félix Fischer <a href="https://rust-lang.github.io/zulip_archive/stream/189540-t-compiler/wg-mir-opt/topic/Debug.20vs.20Release.20opts.html#198595472">(May 24 2020 at 19:04)</a>:</h4>
<p>If a lint stops working for you, your code is rejected and you see it</p>



<a name="198595475"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189540-t-compiler/wg-mir-opt/topic/Debug%20vs%20Release%20opts/near/198595475" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Félix Fischer <a href="https://rust-lang.github.io/zulip_archive/stream/189540-t-compiler/wg-mir-opt/topic/Debug.20vs.20Release.20opts.html#198595475">(May 24 2020 at 19:04)</a>:</h4>
<p>That's the failure mode</p>



<a name="198595484"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189540-t-compiler/wg-mir-opt/topic/Debug%20vs%20Release%20opts/near/198595484" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Félix Fischer <a href="https://rust-lang.github.io/zulip_archive/stream/189540-t-compiler/wg-mir-opt/topic/Debug.20vs.20Release.20opts.html#198595484">(May 24 2020 at 19:05)</a>:</h4>
<p>Whereas if an optimization starts breaking your code, you'll not notice right away. That's a bad failure mode</p>



<a name="198595545"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189540-t-compiler/wg-mir-opt/topic/Debug%20vs%20Release%20opts/near/198595545" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Félix Fischer <a href="https://rust-lang.github.io/zulip_archive/stream/189540-t-compiler/wg-mir-opt/topic/Debug.20vs.20Release.20opts.html#198595545">(May 24 2020 at 19:06)</a>:</h4>
<p>I also would personally prefer to not inherit this thing which is very common in C compilers, which is that optimizations break perfectly sound code. That always sucks to debug. I would love it if we never did that to people, or at least not knowingly.</p>



<a name="198595557"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189540-t-compiler/wg-mir-opt/topic/Debug%20vs%20Release%20opts/near/198595557" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Félix Fischer <a href="https://rust-lang.github.io/zulip_archive/stream/189540-t-compiler/wg-mir-opt/topic/Debug.20vs.20Release.20opts.html#198595557">(May 24 2020 at 19:07)</a>:</h4>
<p>I mean... llvm does that to us already! We cannot use noalias because optimizations break it</p>



<a name="198595604"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189540-t-compiler/wg-mir-opt/topic/Debug%20vs%20Release%20opts/near/198595604" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Félix Fischer <a href="https://rust-lang.github.io/zulip_archive/stream/189540-t-compiler/wg-mir-opt/topic/Debug.20vs.20Release.20opts.html#198595604">(May 24 2020 at 19:08)</a>:</h4>
<p>I would much prefer it if we stopped this tradition of optimizations breaking people's code</p>



<a name="198595606"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189540-t-compiler/wg-mir-opt/topic/Debug%20vs%20Release%20opts/near/198595606" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Félix Fischer <a href="https://rust-lang.github.io/zulip_archive/stream/189540-t-compiler/wg-mir-opt/topic/Debug.20vs.20Release.20opts.html#198595606">(May 24 2020 at 19:08)</a>:</h4>
<p>:P</p>



<a name="198597374"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189540-t-compiler/wg-mir-opt/topic/Debug%20vs%20Release%20opts/near/198597374" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/189540-t-compiler/wg-mir-opt/topic/Debug.20vs.20Release.20opts.html#198597374">(May 24 2020 at 19:57)</a>:</h4>
<p><span class="user-mention silent" data-user-id="212698">Félix Fischer</span> <a href="#narrow/stream/189540-t-compiler.2Fwg-mir-opt/topic/Debug.20vs.20Release.20opts/near/198595604">said</a>:</p>
<blockquote>
<p>I would much prefer it if we stopped this tradition of optimizations breaking people's code</p>
</blockquote>
<p>I can't even say how much I agree with this.^^</p>



<a name="198597440"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189540-t-compiler/wg-mir-opt/topic/Debug%20vs%20Release%20opts/near/198597440" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/189540-t-compiler/wg-mir-opt/topic/Debug.20vs.20Release.20opts.html#198597440">(May 24 2020 at 19:58)</a>:</h4>
<p>Somehow an entire industry came to accept that <code>-O3</code> sometimes breaks your code and that's just what optimizations do. (granted, most of those are probably cases of UB in the program, but there are also more than enough compiler bugs going around.) I don't know how we ended up there, but it's totally awful and really needs fixing. plus, Rust is a safe language, so it should care <em>even more</em> about fixing that.</p>



<a name="198599796"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189540-t-compiler/wg-mir-opt/topic/Debug%20vs%20Release%20opts/near/198599796" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Hanna Kruppe <a href="https://rust-lang.github.io/zulip_archive/stream/189540-t-compiler/wg-mir-opt/topic/Debug.20vs.20Release.20opts.html#198599796">(May 24 2020 at 20:55)</a>:</h4>
<p>I mean, telling users "oh yeah, optimization X has soundness bugs but you can pass <code>-Zwhatever</code> to enable it anyway, it'll probably make your code faster" would be a bad idea, duh. But in a situation where we know of a soundness issue in a MIR optimization and can't fix it promptly, I don't think "remove the optimization" is the best alternative. Removing the code (or at least, any way to run it) just makes it harder to work on a fix: you'd have to revert the removal and then fix up any bitrot that occurred in the mean time before you can even check if a test case for the unsoundness still reproduces. Leaving the optimization available behind a scary hidden flag also avoids miscompiling people's programs, but any existing tests for the pass keep running, mechanical refactors get applied to it, etc. and so development gets easier.</p>
<p>BTW, this isn't too different from "incomplete feature gates", some of which also have soundness issues but we keep them in-tree to enable iterative development and testing.</p>



<a name="198607021"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189540-t-compiler/wg-mir-opt/topic/Debug%20vs%20Release%20opts/near/198607021" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Félix Fischer <a href="https://rust-lang.github.io/zulip_archive/stream/189540-t-compiler/wg-mir-opt/topic/Debug.20vs.20Release.20opts.html#198607021">(May 25 2020 at 00:29)</a>:</h4>
<p>Yep, <span class="user-mention" data-user-id="124289">@Hanna Kruppe</span>, I think I completely agree with you. I think something that's really good about how we work right now, is that all mir optimizations have more or less their own test suite that <strong>always</strong> runs on the CI pipelines for rustc.</p>



<a name="198607072"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189540-t-compiler/wg-mir-opt/topic/Debug%20vs%20Release%20opts/near/198607072" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Félix Fischer <a href="https://rust-lang.github.io/zulip_archive/stream/189540-t-compiler/wg-mir-opt/topic/Debug.20vs.20Release.20opts.html#198607072">(May 25 2020 at 00:31)</a>:</h4>
<p>I would leave them summoneable through some scary flag, just as we do today. Something like <code>-Zwhatever</code> I think is fine.</p>



<a name="198607076"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189540-t-compiler/wg-mir-opt/topic/Debug%20vs%20Release%20opts/near/198607076" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Félix Fischer <a href="https://rust-lang.github.io/zulip_archive/stream/189540-t-compiler/wg-mir-opt/topic/Debug.20vs.20Release.20opts.html#198607076">(May 25 2020 at 00:32)</a>:</h4>
<p>I would definitely never allow unsound opts to get into the stable compiler though</p>



<a name="198607123"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189540-t-compiler/wg-mir-opt/topic/Debug%20vs%20Release%20opts/near/198607123" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Félix Fischer <a href="https://rust-lang.github.io/zulip_archive/stream/189540-t-compiler/wg-mir-opt/topic/Debug.20vs.20Release.20opts.html#198607123">(May 25 2020 at 00:33)</a>:</h4>
<p>And also that enum that <span class="user-mention" data-user-id="119009">@eddyb</span> suggested, I would also change. From:</p>
<div class="codehilite"><pre><span></span><code><span class="k">enum</span> <span class="nc">MirOptLevel</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">    </span><span class="n">Disabled</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="mi">0</span><span class="p">,</span><span class="w"></span>
<span class="w">    </span><span class="nb">Default</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="mi">1</span><span class="p">,</span><span class="w"></span>
<span class="w">    </span><span class="n">Aggressive</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="mi">2</span><span class="p">,</span><span class="w"></span>
<span class="p">}</span><span class="w"></span>
</code></pre></div>


<p>To:</p>
<div class="codehilite"><pre><span></span><code><span class="k">enum</span> <span class="nc">MirOptLevel</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">    </span><span class="n">Disabled</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="mi">0</span><span class="p">,</span><span class="w"></span>
<span class="w">    </span><span class="n">Light</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="mi">1</span><span class="p">,</span><span class="w"></span>
<span class="w">    </span><span class="n">Heavy</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="mi">2</span><span class="p">,</span><span class="w"></span>
<span class="w">    </span><span class="n">Unsound</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="mi">3</span><span class="p">,</span><span class="w"></span>
<span class="p">}</span><span class="w"></span>
</code></pre></div>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>